package com.utils;

public interface Figure {
    Type getType();

    Figure rotate(int times);

    public enum Type {
        I("I") {
            @Override
            public Figure createNewFigure(PlotColor color) {
                return new TetrisFigure(0, 1, color, I, "#", "#", "#", "#");
            }
        }, J("J") {
            @Override
            public Figure createNewFigure(PlotColor color) {
                return new TetrisFigure(1, 1, color, J, " #", " #", "##");
            }
        }, L("L") {
            @Override
            public Figure createNewFigure(PlotColor color) {
                return new TetrisFigure(0, 1, color, L, "# ", "# ", "##");
            }
        }, O("O") {
            @Override
            public Figure createNewFigure(PlotColor color) {
                return new TetrisFigure(0, 0, color, O, "##", "##");
            }
        }, S("S") {
            @Override
            public Figure createNewFigure(PlotColor color) {
                return new TetrisFigure(1, 1, color, S, " ##", "## ");
            }
        }, T("T") {
            @Override
            public Figure createNewFigure(PlotColor color) {
                return new TetrisFigure(1, 1, color, T, " # ", "###");
            }
        }, Z("Z") {
            @Override
            public Figure createNewFigure(PlotColor color) {
                return new TetrisFigure(1, 1, color, Z, "## ", " ##");
            }
        };

        private String name;

        Type(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public abstract Figure createNewFigure(PlotColor color);

        public static Figure getFigure(String figureType, PlotColor color) {
            if (figureType.equals(O.getName())) {
                return O.createNewFigure(color);
            } else if (figureType.equals(I.getName())) {
                return I.createNewFigure(color);
            } else if (figureType.equals(S.getName())) {
                return S.createNewFigure(color);
            } else if (figureType.equals(Z.getName())) {
                return Z.createNewFigure(color);
            } else if (figureType.equals(T.getName())) {
                return T.createNewFigure(color);
            } else if (figureType.equals(L.getName())) {
                return L.createNewFigure(color);
            } else {
                return J.createNewFigure(color);
            }
        }
    }

    int getLeft();

    int getRight();

    int getTop();

    int getBottom();

    int[] getRowCodes(boolean ignoreColors);

    int getWidth();

    Figure getCopy();
}
